$(document).ready(function() {
    var stuNum = getUrlParms("stuNum");
    //console.log(stuNum);
    $.ajax({
        url: "http://localhost:8080/partyMember/queryPartyMemberByPMA",
        type: "GET",
        async: true,
        data: "partyMemberAccount=" + stuNum,
        dataType: "json",
        success: function (data) {
            //console.log(data)

            var partyMember=data.data.partyMember;
            $("#partyMemberAccount").val(partyMember.partyMemberAccount);
            $("#partyMemberName").val(partyMember.partyMemberName);
            // if (partyMember.partyMemberType==1) {
            //     $("#sel").append(" <option value='1' selected='selected' >积极分子</option><option value='2'>发展对象</option><option value='3'>中共预备党员</option><option value='4'>中共党员</option>");
            // }else if (partyMember.partyMemberType==2) {
            //     $("#sel").append(" <option value='1' >积极分子</option><option value='2' selected='selected' >发展对象</option><option value='3'>中共预备党员</option><option value='4'>中共党员</option>");
            // }else if (partyMember.partyMemberType==3) {
            //     $("#sel").append(" <option value='1' >积极分子</option><option value='2'>发展对象</option><option value='3' selected='selected' >中共预备党员</option><option value='4'>中共党员</option>");
            // }else {
            //     $("#sel").append(" <option value='1' >积极分子</option><option value='2'>发展对象</option><option value='3'>中共预备党员</option><option value='4'  selected='selected' >中共党员</option>");
            // }

            $("#sel option[value='"+partyMember.partyMemberType+"']").attr("selected","selected");

        },
        error:function () {
            layer.msg("网络在开小差~稍后重试");
        }
    });

});
//保存
$(document).on('click', '#save-btn', function() {

    var partyMemberAccount = getUrlParms("stuNum");
    var type = getUrlParms("type");
    console.log("partyMemberAccount="+partyMemberAccount);
    var $partyMemberType=$("#sel option:selected").val();
    console.log("$partyMemberType="+$partyMemberType);
    console.log("type="+type);
    //封装成对象提交
    var data = {
        partyMemberAccount:partyMemberAccount,
        typeNow:$partyMemberType,
        typeLast:type,
    };
    $.ajax({
        url: "http://localhost:8080/partyMember/savePartyMember",
        type: "POST",
        async: false,
        data:JSON.stringify(data),
        dataType: "json",
        contentType:"application/json",
        success:function () {
            layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            layer.alert('提交成功!', function(){
                var index = parent.layer.getFrameIndex(window.name);
                setTimeout(function(){
                    parent.layer.close(index)
                }, 2000);
                parent.location.reload()
            });
        },
        error:function () {
            layer.msg("网络在开小差~稍后重试");
        }
    });
});
//提交
$(document).on('click', '#update-btn', function() {

    var partyMemberAccount = getUrlParms("stuNum");
    console.log(partyMemberAccount);
    var $partyMemberType=$("#sel option:selected").val();
    console.log($partyMemberType);
    //封装成对象提交
    var data = {
        partyMemberAccount:partyMemberAccount,
        partyMemberType:$partyMemberType,
    };
    $.ajax({
        url: "http://localhost:8080/partyMember/commitPartyMember",
        type: "POST",
        async: false,
        data:JSON.stringify(data),
        dataType: "json",
        contentType:"application/json",
        success:function () {
            layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            layer.alert('提交成功!', function(){
                var index = parent.layer.getFrameIndex(window.name);
                setTimeout(function(){
                    parent.layer.close(index)
                }, 2000);
                parent.location.reload()
            });
        },
        error:function () {
            layer.msg("网络在开小差~稍后重试");
        }
    });
});



function getUrlParms(name){
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)
        return unescape(r[2]);
    return null;
}

